﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
//IE中要在Internet设置-》高级中选择“打印背景色和图像”！！！
public partial class receipts : BasePage
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Request.QueryString["pnr"] == null)
            {
                Response.Write("Illegal page call!");
                return;
            }
            
            //Response.Write(bar_code39(Request.Form["hidOrderNo"].ToString(), 40, 1, 1));
            Response.Write("<html><head></head><body><center>");
            CRSI.Ticket inst = new CRSI.Ticket();
            int ret_code;
            string ret_msg;
            DataSet dsRet;
            
            int last_pax_sn = -1, curr_pax_sn;//, last_trip_sn=-1;
            string curr_tkt_no="";
            //Table tabReceipts;
            //TableRow tabRow;
            //TableCell tabCell;
            string sell_office="",entity="";
            string pay_currency = "",pay_time="";

            float total_fare=0,fare_roe=1,tax_roe=1;
            //float tkt_fare, taxes, fuel_charge, total_fare;

            dsRet = inst.OrderReceipts(Convert.ToInt64(Request.QueryString["pnr"].ToString()), 2, Application["UID"].ToString(), Application["PWD"].ToString(), out ret_code, out ret_msg);
            if (ret_code < 0)
            {
                Response.Write(ret_msg);
                return;
            }
            if (ret_code > 0)
            {
                switch (ret_code)
                {
                    case 1:
                        Response.Write("订单找不到");
                        break;
                    case 2:
                        Response.Write("无权查看");
                        break;
                    case 3:
                        Response.Write("无查看本Office订单权限");
                        break;
                    case 4:
                        Response.Write("无查看本Entity订单权限");
                        break;
                    case 91:
                        Response.Write("登录错");
                        break;
                    default:
                        Response.Write("未知错误：" + ret_code.ToString());
                        break;
                }
                return;
            }
            foreach (DataRow row in dsRet.Tables[0].Rows)
            {
                curr_pax_sn = Convert.ToInt32(row["pax_sn"]);
                if (curr_pax_sn != last_pax_sn)
                {
                    if (last_pax_sn != -1)
                    {
                        //Response.Write("<tr><td colspan='5' align='center'>" + bar_code128A(curr_tkt_no, 20, 1, 0) + "<br/>票号/Tkt No.: " + curr_tkt_no + "</td><td colspan='2'>总价/Total Fare: <br/>" + pay_currency + total_fare.ToString() + "</td><td colspan='3'>出票点/Agent:<br/>"/* + office_name + "(" */+ entity + "/" + sell_office + "</td><td colspan='3'>支付时间/Pay Time:<br/>" + pay_time + "</td></tr>");
                        Response.Write("<tr><td colspan='5' align='center'><img src='bar_code.aspx?source=" + curr_tkt_no+"&height=15&unit_width=1'><br/>票号/Tkt No.: " + curr_tkt_no + "</td><td colspan='2'>总价/Total Fare: <br/>" + pay_currency + total_fare.ToString() + "</td><td colspan='3'>出票点/Agent:<br/>"/* + office_name + "(" */+ entity + "/" + sell_office + "</td><td colspan='3'>支付时间/Pay Time:<br/>" + pay_time + "</td></tr>");
                        Response.Write("<tr><td colspan='13'>验真网站/Verify Site: http://www.mysite.com </td></tr>");
                        Response.Write("</table><br/><img src='scissors.bmp'><hr style='border:1px dashed black; height:1px' width='50%'><br/>");
                        total_fare = 0;
                    }
                    Response.Write("<table style='border-collapse:collapse' border=1 borderColor='black'><tr><td colspan='13' align='center'><b><br/>行程提醒单/ITINERARY<br/>&nbsp;</b></td></tr><tr><td colspan='3'>姓名/Name:<br/>");
                    //Response.Write(row["family_name"].ToString().Trim()+"/"+row["name"].ToString().Trim()+"</td>");
                    Response.Write(row["family_name"].ToString().Trim() + "/" + row["name"].ToString().Trim() + "<br/>" + row["family_name_en"].ToString().Trim() + "/" + row["name_en"].ToString().Trim() + "</td>");
                    //Response.Write("<td colspan='2'>类型/Pax. Type:<br/>" + row["age_type"] + "</td><td colspan='7' align='center'>" + bar_code128A(row["id_no"].ToString(), 25, 1, 0) + "<br/>证件号/ID: " + row["id_no"].ToString().Trim() + "</td></tr>");
                    Response.Write("<td colspan='2'>年龄/Age:<br/>" + row["age_type"] + "</td><td colspan='2'>有效期至/Expiry:<br/>" + Convert.ToDateTime(row["expiry"]).ToShortDateString() + "</td><td colspan='6' align='center'><img src='bar_code.aspx?source=" + row["id_no"].ToString() + "&height=20&unit_width=1'><br/>证件号/ID: " + row["id_no"].ToString().Trim() + "</td></tr>");
                    //Response.Write("<tr><td colspan='4'>支付时间/Pay Time:" + row["pay_time"].ToString() + "</td><td colspan='3'>支付币种/Currency:" + row["pay_currency"] + "</td><td colspan='3'>票价兑换率/Fare ROE:" + row["fare_roe"] + "</td><td colspan='3'>税兑换率/Tax ROE:" + row["tax_roe"] + "</td></tr>");
                    //Response.Write("<td colspan='2'>Order: " + Request.QueryString["bk_id"].ToString() + "</td></tr>");

                    //tabReceipts = new Table();
                    //tabRow = new TableRow();
                    //tabCell = new TableCell();
                    last_pax_sn = curr_pax_sn;
                    //last_trip_sn = -1;
                    Response.Write("<tr><td>S/N</td><td>航程<br/>From-To</td><td>航班<br/>Flight</td><td>日期<br/>Date</td><td>起飞时间<br/>Dep. At</td><td>到达时间<br/>Arr. At</td><td>舱位/子舱<br/>Cabin/Class</td><td>票价代码<br/>Fare Code</td><td>票价<br/>Tkt. Price</td><td>附加费<br/>Fuel Charge</td><td>税<br/>Taxes</td><td>免费行李<br/>Bag. Allow</td></tr>");//<tr><td>&nbsp;</td><td colspan='2'>Baggage Allow</td><td colspan='4'>Check-in No.</td></tr>");
                }
                //if(last_trip_sn==-1)
                //    Response.Write("<tr><td>S/N</td><td>From-To</td><td>Flight</td><td>Cabin/Class</td><td>Dep. Time</td><td>Fare Code</td><td>Tkt. Price</td><td>Taxes</td><td>Fuel Charge</td></tr>");//<tr><td>&nbsp;</td><td colspan='2'>Baggage Allow</td><td colspan='4'>Check-in No.</td></tr>");

                //tkt_fare = Convert.ToSingle(row["final_price"]);
                //taxes = Convert.ToSingle(row["final_taxes"]);
                //fuel_charge = Convert.ToSingle(row["final_fuel"]);
                //total_fare = total_fare + tkt_fare + taxes + fuel_charge;
                sell_office = row["sell_office"].ToString();
                //office_name = row["name"].ToString().Trim();
                //pay_time = row["pay_time"].ToString();
                entity=row["sell_entity"].ToString();
                curr_tkt_no = Convert.ToInt64(row["tkt_no"]).ToString();
                fare_roe = Convert.ToSingle(row["fare_roe"]);
                tax_roe = Convert.ToSingle(row["tax_roe"]);
                pay_currency = row["pay_currency"].ToString();
                pay_time = row["pay_time"].ToString();

                Response.Write("<tr><td>" + row["trip_sn"].ToString() + "</td><td>" + row["ori_city"] + "- " + row["des_city"] + "</td><td>" + row["airline"] + row["flt_no"] + "</td><td>" + Convert.ToDateTime(row["dep_time"]).ToShortDateString() + "</td>");
                Response.Write("<td>" + Convert.ToDateTime(row["dep_time"]).ToShortTimeString() + "</td><td>" + Convert.ToDateTime(row["arr_time"]).ToShortTimeString() + "</td><td>" + row["cabin"] + "/" + row["class"] + "</td><td>" + row["fare_code"] + "</td><td>" + row["fare_currency"] + Convert.ToSingle(row["final_price"]).ToString() + "</td><td>" + row["fare_currency"] + Convert.ToSingle(row["final_fuel"]).ToString() + "</td><td>" + row["tax_currency"] + Convert.ToSingle(row["final_taxes"]).ToString() + "</td>");
                total_fare = total_fare + (Convert.ToSingle(row["final_price"]) + Convert.ToSingle(row["final_fuel"]) + Convert.ToSingle(row["other_fee"])) * Convert.ToSingle(row["fare_roe"]) + Convert.ToSingle(row["final_taxes"]) * Convert.ToSingle(row["tax_roe"]);
                //Response.Write("<tr><td>&nbsp;</td><td>Baggage Allow:<br/>");
                Response.Write("<td>");
                if (row["age_type"].ToString() == "A")
                    Response.Write(row["free_baggage"]);
                else if(row["age_type"].ToString()=="C")
                    Response.Write(row["chd_baggage"]);
                else if (row["age_type"].ToString() == "I")
                    Response.Write(row["inf_baggage"]);
                //tkt_no = Request.QueryString["bk_id"].ToString() + "-" + row["pax_sn"].ToString().PadLeft(3, '0') + "-" + row["trip_sn"].ToString();
                Response.Write("</td></tr>");//<td colspan='7' align='center'>" + bar_code128A(row["id_no"].ToString(), 25, 1, 0) + "<br/>Self-service Code: " + row["id_no"].ToString() + "</td></tr>");

            }
            //Response.Write("<tr><td colspan='5' align='center'>" + bar_code128A(curr_tkt_no, 20, 1, 0) + "<br/>票号/Tkt No.: " + curr_tkt_no + "</td><td colspan='2'>总价/Total Fare: <br/>" + pay_currency + total_fare.ToString() + "</td><td colspan='3'>出票点/Agent:<br/>"/* + office_name + "(" */+ entity + "/" + sell_office + "</td><td colspan='3'>支付时间/Pay Time:<br/>" + pay_time + "</td></tr>");
            Response.Write("<tr><td colspan='5' align='center'><img src='bar_code.aspx?source=" + curr_tkt_no + "&height=15&unit_width=1'><br/>票号/Tkt No.: " + curr_tkt_no + "</td><td colspan='2'>总价/Total Fare: <br/>" + pay_currency + total_fare.ToString() + "</td><td colspan='3'>出票点/Agent:<br/>"/* + office_name + "(" */+ entity + "/" + sell_office + "</td><td colspan='3'>支付时间/Pay Time:<br/>" + pay_time + "</td></tr>");
            Response.Write("<tr><td colspan='13'>验真网站/Verify Site: http://www.mysite.com </td></tr>");
            Response.Write("</table>&nbsp;<br/>&nbsp;<br/>");
            Response.Write("</center></body></html>");
        }
    }

    

    
}
